package com.hw.paltfrom.service.mainscreen;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hw.paltfrom.mapper.*;
import com.hw.paltfrom.utils.ResponeResultUtil;
import com.hw.paltfrom.vo.MidScrSvWorkflowVo;
import com.hw.paltfrom.vo.MidScrZHDDWorkflowVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.mapper.HwBaseEnterpriseMapper;
import com.hw.paltfrom.mapper.HwBaseOffsiteMapper;
import com.hw.paltfrom.mapper.HwBaseOverrunstationMapper;
import com.hw.paltfrom.mapper.HwDataEnterpriseMapper;
import com.hw.paltfrom.mapper.HwDataOffsiteMapper;
import com.hw.paltfrom.mapper.HwDataOverrunstationMapper;
import com.hw.paltfrom.pack.ResponseResult;
import com.hw.paltfrom.pojo.HwBaseEnterprise;
import com.hw.paltfrom.pojo.HwBaseOffsite;
import com.hw.paltfrom.pojo.HwBaseOverrunstation;
import com.hw.paltfrom.pojo.HwDataEnterprise;
import com.hw.paltfrom.pojo.HwDataOffsite;
import com.hw.paltfrom.pojo.HwDataOverrunstation;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.DateTimeUtil;

@Service
public class CenterScreenServer {

	@Autowired
	private HwBaseOverrunstationMapper hbosMapper;
	@Autowired
	private HwBaseEnterpriseMapper hbepMapper;
	@Autowired
	private HwBaseOffsiteMapper baseoffsiteMapper;
	@Autowired
	private HwDataOverrunstationMapper hdosMapper;
	@Autowired
	private HwDataOffsiteMapper hdofMapeer;
	@Autowired
	private HwDataEnterpriseMapper hdeMapper;
	@Autowired
	private HwCommandWorkflowMapper commandWorkflowMapper;

//	查询所有站信息
	public Map<String, Object> queryStations() {
		Wrapper<HwBaseOverrunstation> datawrapper = new EntityWrapper<HwBaseOverrunstation>();
		datawrapper.eq("F_DeleteMark", "0").eq("F_EnabledMark", "1");
		List<HwBaseOverrunstation> selectList = hbosMapper.selectList(datawrapper);
		return ResponseResult.successNotice(HWSystemCode.SUCCESS, selectList);
	}
//	查询所有源头企业
	public Map<String, Object> queryEnterprises() {
		Wrapper<HwBaseEnterprise> datawrapper = new EntityWrapper<HwBaseEnterprise>();
		datawrapper.eq("F_DeleteMark", "0").eq("F_EnabledMark", "1");
		List<HwBaseEnterprise> selectList = hbepMapper.selectList(datawrapper);
		return ResponseResult.successNotice(HWSystemCode.SUCCESS, selectList);
	}

//	查询所有非现场监测点

	public Map<String, Object> queryOffsite() {
		Wrapper<HwBaseOffsite> datawrapper = new EntityWrapper<HwBaseOffsite>();
		datawrapper.eq("F_DeleteMark", "0").eq("F_EnabledMark", "1");
		List<HwBaseOffsite> selectList =baseoffsiteMapper.selectList(datawrapper);
		return ResponseResult.successNotice(HWSystemCode.SUCCESS, selectList);
	}

//	查当天超限站 、非现场、源头企业、的车辆总数
	public Map<String, Object> queryCars() {
		
		HashMap<String, Object> result = new HashMap<String, Object>();
		
		HashMap<String, Long> afterTimeRound = DateTimeUtil.getAfterTimeRound(0);
		Timestamp startTime =new Timestamp(afterTimeRound.get("startTime")) ;
		Timestamp endTime =new Timestamp(afterTimeRound.get("endTime")) ;
		
		Wrapper<HwDataOverrunstation> overRunWrapper=new EntityWrapper<HwDataOverrunstation>();
		overRunWrapper.between("D_JCSJ", startTime, endTime);
		Integer owCount = hdosMapper.selectCount(overRunWrapper);
		result.put("owCount", owCount);
//		List<HwDataOverrunstation> owList = hdosMapper.selectList(overRunWrapper);
		
		Wrapper<HwDataOffsite> offsiteWrapper=new EntityWrapper<HwDataOffsite>();
		offsiteWrapper.between("JCSJ", startTime, endTime);
		Integer ofCount = hdofMapeer.selectCount(offsiteWrapper);
		result.put("ofCount", ofCount);
//		List<HwDataOffsite> ofList = hdofMapeer.selectList(offsiteWrapper);
		
		Wrapper<HwDataEnterprise> deWrapper=new EntityWrapper<HwDataEnterprise>();
		deWrapper.between("JCSJ", startTime, endTime);
		Integer deCount = hdeMapper.selectCount(deWrapper);
		result.put("deCount", deCount);
//		List<HwDataEnterprise> deList = hdeMapper.selectList(deWrapper);
		
		return ResponseResult.successNotice(HWSystemCode.SUCCESS, result);

	}

	//	查全市最近10条创建检查督导任务流。
	public Map<String, Object> queryCreatedSvTasks() {
		List<MidScrSvWorkflowVo> midScrSvWorkflowVos = commandWorkflowMapper.queryMidScrCreatedSvWorkflow();
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS,midScrSvWorkflowVos);
	}
	//	查全市最近10条更新检查督导任务流。
	public Map<String, Object> queryUpdateSvTasks() {
		List<MidScrSvWorkflowVo> midScrSvWorkflowVos = commandWorkflowMapper.queryMidScrUpdateSvWorkflow();
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS,midScrSvWorkflowVos);
	}
    //	查全市最近10条创建指挥调度任务流。
    public Map<String, Object> queryCreatedZhddTasks() {
        List<MidScrZHDDWorkflowVo> midScrZHDDWorkflowVos = commandWorkflowMapper.queryMidScrCreatedZhddWorkflow();
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS,midScrZHDDWorkflowVos);
    }
    //	查全市最近10条更新指挥调度任务流。
    public Map<String, Object> queryUpdateZhddTasks() {
        List<MidScrZHDDWorkflowVo> midScrZHDDWorkflowVos = commandWorkflowMapper.queryMidScrUpdateZhddWorkflow();
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS,midScrZHDDWorkflowVos);
    }
}
